//------------------------------------------------------------------------------
#include <QDir>
#include <QApplication>
#include <QtDebug>
#include "CProfil.h"
#include "CConfDefaultReader.h"
#include "CCrypt.h"
//------------------------------------------------------------------------------
CProfil::CProfil(QSettings *settings, QString name) {
	_settings=settings;
	_name=name;
	read();
}
//------------------------------------------------------------------------------
CProfil::~CProfil(void) {}
//------------------------------------------------------------------------------
void CProfil::read(void) {
	CConfDefaultReader *confDefaultReader=CConfDefaultReader::getInstance();
	QString authPluginName=confDefaultReader->getParamValue("authPluginName");
	
	#ifdef WIN32
	authPluginName+=".dll";
	#else
	authPluginName+=".so";
	#endif
	
	_base=_settings->value(_name+"_base", confDefaultReader->getParamValue("base")).toString();
	_jasper=_settings->value(_name+"_jasper", confDefaultReader->getParamValue("jasper")).toString();
	lasts=_settings->value(_name+"_lasts").toHash();
	_user=_settings->value(_name+"_user", "").toString();
	_storePassword=_settings->value(_name+"_storePassword", "").toBool();
	_password=_settings->value(_name+"_password", "").toString();
}
//------------------------------------------------------------------------------
void CProfil::write(void) {
	_settings->setValue(_name+"_base", _base);
	_settings->setValue(_name+"_jasper", _jasper);
	_settings->setValue(_name+"_user", _user);
	_settings->setValue(_name+"_storePassword", _storePassword);
	_settings->setValue(_name+"_password", _storePassword ? _password : "");
	_settings->setValue(_name+"_lasts", lasts);
}
//------------------------------------------------------------------------------
bool CProfil::getLast(QString what, QString &last)
{
	if(lasts.find(what) == lasts.end()) {
		return false;
	}
	last=lasts[what].toString();
	return true;
}
//------------------------------------------------------------------------------
bool CProfil::getLast(QString what, QMap<QString, QVariant> &lastKeyValues) {
	if(lasts.find(what) == lasts.end()) {
		return false;
	}
	lastKeyValues=lasts[what].toMap();
	return true;
}
//------------------------------------------------------------------------------
void CProfil::setLast(QString what, QString value) {
	lasts[what]=QVariant(value);
}
//------------------------------------------------------------------------------
void CProfil::setLast(QString what, QMap<QString, QVariant> keyValues) {
	lasts[what]=QVariant(keyValues);
}
//------------------------------------------------------------------------------